﻿package mortal.game.view.skill.panel
{
    import com.mui.controls.*;
    import com.mui.display.*;
    import com.mui.utils.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.pageSelect.*;
    import mortal.game.view.skill.*;
    import mortal.game.view.skill.panel.render.*;

    public class SkillBasicPanel extends GSprite implements ISkillSubPanel
    {
        private var _items:Array;
        private var _line:ScaleBitmap;
        private var _page:PageSelecter;
        private var _lastItem:SkillBasicItem;
        private var _desc:SkillLearnDescForBasic;
        public static const pageNum:int = 10;
        public static const LineNum:int = 5;

        public function SkillBasicPanel()
        {
            return;
        }// end function

        public function setSelected(param1:SkillBasicItem) : void
        {
            if (this._lastItem != null)
            {
                this._lastItem.selected = false;
            }
            this.updateSkillInfo(param1.skillInfo);
            this._lastItem = param1;
            this._lastItem.selected = true;
            return;
        }// end function

        public function updateSkillInfo(param1:SkillInfo) : void
        {
            this._desc.updateData(param1);
            return;
        }// end function

        public function selectIndex(param1:int) : void
        {
            return;
        }// end function

        public function getItemByPos(param1:int) : SkillItem
        {
            var _loc_3:SkillBasicItem = null;
            var _loc_2:int = 0;
            while (_loc_2 < this._items.length)
            {
                
                _loc_3 = this._items[_loc_2] as SkillBasicItem;
                if (_loc_3 != null && _loc_3.skillInfo != null)
                {
                    if (_loc_3.skillInfo.position == param1)
                    {
                        return _loc_3.skillItem;
                    }
                }
                _loc_2++;
            }
            return null;
        }// end function

        public function set allSkillInfos(param1:Array) : void
        {
            var _loc_3:SkillBasicItem = null;
            var _loc_4:SkillInfo = null;
            var _loc_2:int = 0;
            while (_loc_2 < pageNum)
            {
                
                _loc_3 = this._items[_loc_2];
                _loc_4 = param1[_loc_2];
                if (_loc_4 != null)
                {
                    this.addChild(_loc_3);
                    _loc_3.skillInfo = _loc_4;
                }
                else
                {
                    DisplayUtil.removeMe(_loc_3);
                }
                _loc_2++;
            }
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            var _loc_2:SkillBasicItem = null;
            super.createDisposedChildrenImpl();
            this.mouseChildren = true;
            this.mouseEnabled = true;
            pushUIToDisposeVec(UIFactory.bg(0, 0, 686, 474, this));
            this._items = [];
            var _loc_1:int = 0;
            while (_loc_1 < pageNum)
            {
                
                _loc_2 = UICompomentPool.getUICompoment(SkillBasicItem) as SkillBasicItem;
                pushUIToDisposeVec(_loc_2);
                this._items.push(_loc_2);
                _loc_2.index = _loc_1;
                _loc_2.x = _loc_1 % LineNum * 136 + 1;
                _loc_2.y = int(_loc_1 / LineNum) * 213 + 12;
                this.addChild(_loc_2);
                _loc_2.configEventListener(MouseEvent.CLICK, this.clickItemHandler);
                _loc_2.configEventListener(MouseEvent.MOUSE_OVER, this.mouseOverItemHandler);
                _loc_2.configEventListener(MouseEvent.MOUSE_OUT, this.mouseOutItemHandler);
                _loc_1++;
            }
            this._desc = UICompomentPool.getUICompoment(SkillLearnDescForBasic) as SkillLearnDescForBasic;
            this._desc.x = 686;
            this.addChild(this._desc);
            this._line = UIFactory.bg(0, 434, 681, 2, this, ImagesConst.SplitLine);
            this._page = UIFactory.pageSelecter(272, 447, this, PageSelecter.CompleteMode);
            this._page.maxPage = 1;
            this._page.currentPage = 1;
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._desc.dispose(param1);
            this._desc = null;
            this._line.dispose(param1);
            this._line = null;
            this._page.dispose(param1);
            this._page = null;
            return;
        }// end function

        private function clickItemHandler(event:MouseEvent) : void
        {
            var _loc_2:* = event.currentTarget as SkillBasicItem;
            this.setSelected(_loc_2);
            return;
        }// end function

        private function mouseOverItemHandler(event:MouseEvent) : void
        {
            var _loc_2:* = event.target as SkillBasicItem;
            if (_loc_2 != null)
            {
                _loc_2.updateSelectedView(true);
            }
            return;
        }// end function

        private function mouseOutItemHandler(event:MouseEvent) : void
        {
            var _loc_2:* = event.target as SkillBasicItem;
            if (_loc_2 != null)
            {
                _loc_2.selected = _loc_2.selected;
            }
            return;
        }// end function

    }
}
